//重推
define(function() {

	var ViewModel = function() {
		var self = this;
		self.galleryUploader = new qq.FineUploader({
	        debug: true,
	        element: document.getElementById('fine-uploader'),
	        request: { endpoint: '/FileUpload/UploadFile', method: 'POST' },
	        validation: {
	            allowedExtensions: ['xls', 'xlsx']
	        },
	        callbacks: {
	            onAllComplete: function (successIDs, failIDs) {
	                console.log(successIDs);
	            },
	            onComplete: function (id, fileName, responseJSON) {
	                layer.alert('文件上传完成，解析中...', {
	                    icon: 16,
	                    shade: 0.6
	                });
	               var  uploadId = responseJSON.uploadId;
	                $.cookie('uploadId', responseJSON.uploadId, { path: '/',expires:30 });
	            },
	            onUpload: function () {
	                layer.alert('文件上传中', {
	                    icon: 16,
	                    shade: 0.6
	                });
	            }
	        }
	    });

		// 发送数据
		self.send = function() {
			var data ={};
			data.uploadId = parseInt( $.cookie('uploadId'));
			var list =[];
			var groupCheckbox=$("input[name='check']");
		    for(i=0;i<groupCheckbox.length;i++){
		        if(groupCheckbox[i].checked){
		            var val =groupCheckbox[i].value;
		            console.log(val);
		            list.push(val);
		        }
		    }
		    data.list=list;
			console.log(data);
			$.ajax({
				url : '/order/repush/send',
				method : 'POST',
				contentType : 'application/json',
				data : JSON.stringify(data),
				success : function() {
					layer.closeAll();
					layer.msg('三单信息正在推送中...', {
						icon : 16,
						shade : 0.8
					});
				},
				error : function() {
					layer.alert('生成三单出现错误，请联系管理员', {
						icon : 2
					});
				}
			});
		};
		// 初始化
		self.init = function() {
			var uploadId = $.cookie('uploadId');
			console.log(uploadId);
		};

		self.init();
	}

	var model = new ViewModel();
	ko.applyBindings(model);
});